package com.ruoyi.am.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.am.domain.AmCarNum;
import com.ruoyi.am.service.IAmCarNumService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车牌号码管理Controller
 * 
 * @author hkkk
 * @date 2020-12-17
 */
@Controller
@RequestMapping("/am/num")
public class AmCarNumController extends BaseController
{
    private String prefix = "am/num";

    @Autowired
    private IAmCarNumService amCarNumService;

    @RequiresPermissions("am:num:view")
    @GetMapping()
    public String num()
    {
        return prefix + "/num";
    }

    /**
     * 查询车牌号码管理列表
     */
    @RequiresPermissions("am:num:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AmCarNum amCarNum)
    {
        startPage();
        List<AmCarNum> list = amCarNumService.selectAmCarNumList(amCarNum);
        return getDataTable(list);
    }

    /**
     * 导出车牌号码管理列表
     */
    @RequiresPermissions("am:num:export")
    @Log(title = "车牌号码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AmCarNum amCarNum)
    {
        List<AmCarNum> list = amCarNumService.selectAmCarNumList(amCarNum);
        ExcelUtil<AmCarNum> util = new ExcelUtil<AmCarNum>(AmCarNum.class);
        return util.exportExcel(list, "num");
    }

    /**
     * 新增车牌号码管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车牌号码管理
     */
    @RequiresPermissions("am:num:add")
    @Log(title = "车牌号码管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AmCarNum amCarNum)
    {
        return toAjax(amCarNumService.insertAmCarNum(amCarNum));
    }

    /**
     * 修改车牌号码管理
     */
    @GetMapping("/edit/{carId}")
    public String edit(@PathVariable("carId") Long carId, ModelMap mmap)
    {
        AmCarNum amCarNum = amCarNumService.selectAmCarNumById(carId);
        mmap.put("amCarNum", amCarNum);
        return prefix + "/edit";
    }

    /**
     * 修改保存车牌号码管理
     */
    @RequiresPermissions("am:num:edit")
    @Log(title = "车牌号码管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AmCarNum amCarNum)
    {
        return toAjax(amCarNumService.updateAmCarNum(amCarNum));
    }

    /**
     * 删除车牌号码管理
     */
    @RequiresPermissions("am:num:remove")
    @Log(title = "车牌号码管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(amCarNumService.deleteAmCarNumByIds(ids));
    }

    @GetMapping("/getList")
    @ResponseBody
    public String getList(){
        List<AmCarNum> list = amCarNumService.selectAmCarNumList(new AmCarNum());
        StringBuilder res= new StringBuilder();
        for(AmCarNum amCarNum:list){
            res.append(amCarNum.getCarNum()).append(",");
        }
        return res.toString();
    }

}
